﻿using System.Globalization;
using System.Text;
using System.Xml.Linq;
using TVersityDotNet.MediaLib;
using TVersityDotNet.Responses;

namespace TVersityDotNet.Requests
{
    public class BrowseRequest : TVersityRequest
    {
        private BrowseOptions _browseOptions;

        public BrowseRequest(BrowseOptions browseOptions)
        {
            base.Path = "medialib/browse";
            this._browseOptions = browseOptions;
        }

        public override string RequestString
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (string key in this._browseOptions.PropertyBag.PropertiesWithValues.Keys)
                {
                    sb.AppendFormat("{0}={1}&", key, this._browseOptions.PropertyBag.PropertiesWithValues[key]);
                }

                // Remove last &
                sb.Remove(sb.Length - 1, 1);
                return string.Format(CultureInfo.InvariantCulture, "{0}?{1}", this.Path, sb.ToString());
            }
        }

        public override TVersityResponse CreateResponse(XDocument xmlDocument)
        {
            MediaLibResponse response = new MediaLibResponse(xmlDocument);
            return response;
        }
    }
}
